// pages/usercenter/usercenter.js
const app = getApp()
var config = require('../../utils/config.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    repliedCount: 0,
    unansweredCount: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.unanswered();
    this.getReplied();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
  unanswered: function() {
    // 请求未回复列表

    var that = this;
    var url = config.service.reply;

    var phone = app.globalData.phoneNumber;

    wx.request({
      url: url,
      data: {
        timestamp: 12345678,
        sign: "793f06725fce33948526229e42cb7ba7",
        username: app.globalData.phoneNumber,
        is_reply: 1,
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        var data = res.data;
        var code = data.code;
        if (code == 200) {
          var arrays = data.data;
          app.globalData.unansweredData = arrays;

          that.setData({
            unansweredCount: arrays.length
          })
        } else {
          that.setData({
            repliedCount: 0
          })
        }
      },
      fail: function(res) {

      },
      complete: function(res) {},
    })
  },
  getReplied: function() {
    var that = this;
    // 请求未回复列表
    var url = config.service.reply;
    // 请求回复列表
    wx.request({
      url: url,
      data: {
        timestamp: 12345678,
        sign: "793f06725fce33948526229e42cb7ba7",
        username: app.globalData.phoneNumber,
        is_reply: 2,
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        console.log(res);
        var data = res.data;
        var code = data.code;
        if (code == 200) {
          var arrays = data.data;

          app.globalData.repliedData = arrays;
          that.setData({
            repliedCount: arrays.length
          })
        } else {
          that.setData({
            repliedCount: 0
          })
        }
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  }
})